package cn.rengy.web.framework.support;
//package com.uniontrip.framework.support;
//
//import java.io.IOException;
//import java.io.InputStream;
//import java.lang.reflect.Type;
//
//import org.apache.commons.io.IOUtils;
//import org.springframework.core.MethodParameter;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpInputMessage;
//import org.springframework.http.converter.HttpMessageConverter;
//import org.springframework.web.bind.annotation.ControllerAdvice;
//import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice;
///**
// * body数据预处理，如请求数据解密
// * @author rengy
// *
// */
//@ControllerAdvice
//public class DecodeRequestBodyAdvice implements RequestBodyAdvice  {
//
//	@Override
//	public boolean supports(MethodParameter methodParameter, Type targetType,
//			Class<? extends HttpMessageConverter<?>> converterType) {
//		// TODO Auto-generated method stub
//		return true;
//	}
//
//	@Override
//	public Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter,
//			Type targetType, Class<? extends HttpMessageConverter<?>> converterType) {
//		// TODO Auto-generated method stub
//		return body;
//	}
//
//	@Override
//	public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
//			Class<? extends HttpMessageConverter<?>> converterType) throws IOException {
//		// TODO Auto-generated method stub
//		return new MyHttpInputMessage(inputMessage);
//	}
//
//	@Override
//	public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
//			Class<? extends HttpMessageConverter<?>> converterType) {
//		// TODO Auto-generated method stub
//		return body;
//	}
//
//	class MyHttpInputMessage implements HttpInputMessage {
//        private HttpHeaders headers;
//
//        private InputStream body;
//
//        public MyHttpInputMessage(HttpInputMessage inputMessage) throws Exception {
//            this.headers = inputMessage.getHeaders();
//            this.body = IOUtils.toInputStream(AESOperator.getInstance().decrypt(IOUtils.toString(inputMessage.getBody(), "UTF-8")), "UTF-8");
//        }
//
//        @Override
//        public InputStream getBody() throws IOException {
//            return body;
//        }
//
//        @Override
//        public HttpHeaders getHeaders() {
//            return headers;
//        }
//    }
//
//}
